//
//  TemplateFoundDetailsFooterView.m
//  YuTang
//
//  Created by 葛悦彣 on 2024/7/18.
//

#import "TemplateFoundDetailsFooterView.h"
@interface  TemplateFoundDetailsFooterView ()<UITextViewDelegate>

@property (nonatomic ,strong) UILabel * name;
@property (nonatomic ,strong) UILabel * StrLab;
@property (nonatomic ,strong) IQTextView * textview;


@end
@implementation TemplateFoundDetailsFooterView

+ (instancetype)NewView {
    TemplateFoundDetailsFooterView * view = [TemplateFoundDetailsFooterView new];
    view.clipsToBounds = YES;
    view.backgroundColor = UIColor.clearColor;
    [view newUI];
    return view;
}
- (void)newUI{
    
    UIView * backview = [UIView new];
    backview.backgroundColor = UIColor.whiteColor;
    [self addSubview:backview];
    [backview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.right.left.offset(0);
        make.bottom.offset(kwt(-10));
    }];
    
    UIView * makeview = [UIView new];
    makeview.backgroundColor = KcolorHex(@"#F6F7F9");
    [DTKTool YJ:kwt(5) andView:makeview];
    [backview addSubview:makeview];
    [makeview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(0);
        make.bottom.right.offset(kwt(-10));
        make.left.offset(kwt(10));
    }];
    
    UILabel * name = [DTKTool labelWithText:@"任务说明" andFont:kCFont(18) andTextColor:KcolorHex(@"#222222")];
    [makeview addSubview:name];
    self.name = name;
    [name mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(12));
        make.top.offset(kwt(14));
    }];
    
    UILabel * StrLab = [DTKTool labelWithText:@"0/140" andFont:kFont(17) andTextColor:KcolorHex(@"#787A79")];
    [makeview addSubview:StrLab];
    self.StrLab = StrLab;
    [StrLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(kwt(-12));
        make.centerY.equalTo(name);
    }];
    
    UIView * line = [UIView new];
    line.backgroundColor = KcolorHex(@"#DBDBDB");
    [makeview addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(10));
        make.right.offset(kwt(-10));
        make.top.offset(kwt(40));
        make.height.offset(0.5);
    }];
    
    
    IQTextView * textview = [IQTextView new];
    textview.textColor = KcolorHex(@"#222222");
    textview.font = kFont(17);
    textview.delegate = self;
    textview.backgroundColor = UIColor.clearColor;
    self.textview = textview;
    [makeview addSubview:textview];
    [textview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(10));
        make.right.offset(kwt(-10));
        make.top.offset(kwt(50));
        make.bottom.offset(kwt(-10));
    }];
}

- (void)setModel:(TemplateFoundDetailsTaskTypeModelListModel *)model{
    _model = model;
    self.StrLab.text = [NSString stringWithFormat:@"%lu/140",(unsigned long)model.Description.length];
    self.textview.text = model.Description;
    
}
-(void)textViewDidChange:(UITextView *)textView{
    if(textView.text.length > 140){
        textView.text = [textView.text substringToIndex:140];
    }
    self.StrLab.text = [NSString stringWithFormat:@"%lu/140",(unsigned long)textView.text.length];
}
- (void)textViewDidEndEditing:(UITextView *)textView {
    self.model.Description = textView.text;
}
@end
